package lesson02;

/**
 * 线程名
 */
public class Demo_202 {
    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> {
            while(true){
                String name = Thread.currentThread().getName();
                System.out.println(name + "  :hello thread1....");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        //线程2  赋予名字
        Thread thread2 = new Thread(() -> {
            String name = Thread.currentThread().getName();
            while(true){
                System.out.println(name+"  hello thread2.....");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        },"线程2");
        //启动线程
        System.out.println(Thread.currentThread().getName());
        System.out.println(thread1.getName());
        System.out.println(thread2.getName());
        thread1.start();
        thread2.start();
    }

}
